﻿using ExcelParser.Reader;
using ExcelParser.Writer;
using System.Collections.Generic;

namespace ExcelParser.CodeGen
{
    public class Config
    {
        public string Name { get; set; }
        public CodeWriter Writer { get; private set; }

        private Dictionary<string, ExcelField> m_fields;

        public Config(CodeWriter writer)
        {
            Writer = writer;
            m_fields = new Dictionary<string, ExcelField>();
        }

        public void AddField(string name, ExcelField field)
        {
            if (field == null)
                return;

            m_fields.Add(name, field);
        }

        public string GenCode(ExcelSheet sheet)
        {
            return Writer.GenCode(sheet, Name, m_fields.Values);
        }

        public ExcelField FindField(string fieldName)
        {
            ExcelField field;
            m_fields.TryGetValue(fieldName, out field);
            return field;
        }
    }
}